package com.fast.cms.web.mobile;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fast.base.model.AnoSysLog;
import com.fast.base.db.sql.AbstractSqlGenerator;
import com.fast.base.util.LogUtils;
import com.fast.base.util.StringUtils;
import com.fast.base.db.page.PageView;
import com.fast.base.util.web.ResponseData;
import com.fast.base.util.web.ResponseEnum;
import com.fast.base.web.BaseController;
import com.fast.cms.model.article.NoticeInfo;
import com.fast.cms.model.system.Dictionary;
import com.fast.cms.service.article.NoticeInfoService;
import com.fast.cms.web.form.CheckNoticeInfoForm;
import com.fast.cms.web.form.NoticeInfoForm;
import com.fast.user.model.admin.AdminUser;

/**
 * ClassName:NoticeInfoController <br/>
 * 用途:NoticeInfo信息控制处理 <br/>
 * 开发人员：lushuifa http://lushuifa.iteye.com/ 邮箱:lsflu@126.com
 * @version
 * @since JDK 1.6
 * @see Date: 2015年03月14日 23时37分17秒 <br/>
 */
@Controller
@RequestMapping("/app/noticeInfo")
public class AppNoticeInfoController extends BaseController{
	
	private Log log = LogFactory.getLog(AppNoticeInfoController.class);
	
	@Resource(name="noticeInfoService")
	private NoticeInfoService noticeInfoService;
	
	/**
	 * 得到[公告信息]列表
	 * @return PageView<NoticeInfo>
	 * @throws IOException 
	 */
	@ResponseBody
	@RequestMapping(value="/getNoticeInfoList.do", method=RequestMethod.POST)
	public Map<String,Object> getNoticeInfoList(NoticeInfoForm noticeInfoForm) {
		Map<String,Object> gridMap = new HashMap<String,Object>();
		try{
			PageView<NoticeInfo> pageView = this.noticeInfoService.getNoticeInfoList(noticeInfoForm);
			gridMap.put("total", pageView.getTotalRecord());
			gridMap.put("rows", pageView.getRecords());
		}catch (Exception e) {
			LogUtils.error("getNoticeInfoList err:",e);
			e.printStackTrace();
			return null;
		}
 		return gridMap;
	}
	
	/**
	 * 审批公告
	 * @param checkArticleForm
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/checkNoticeInfo.do")
	public ResponseData checkNoticeInfo(CheckNoticeInfoForm checkNoticeInfoForm){
		ResponseData j = new ResponseData();
		boolean actionFlag = this.noticeInfoService.checkNoticeInfo(checkNoticeInfoForm);
		if(actionFlag){
			//审核机关操作 审核通过时则应该扣除库存
			j.buildSuccessResponse();
		}else{
			j.setCode("01");
			j.setMsg("操作失败,请重试或者重新登录试试！");
		}
		return j;
	}
	
	/**
	 * 说明:限量查询通知列表 <br>
	 * 编写者:lushuifa
	 * 创建时间:2017年7月13日 下午11:07:16 </pre>
	 * @param 
	 * @return ResponseData 说明
	 */
	@ResponseBody
	@RequestMapping({"/getNoticeListForLimit.do"})
	public ResponseData getNoticeListForLimit(String noticeTypeId,int limitSize,String selectType){
		ResponseData responseData = new ResponseData();
		try{
			List<Map<String, Object>> articleList = this.noticeInfoService.getNoticeListForLimit(noticeTypeId, limitSize, selectType);
			responseData.setData(articleList);
		}catch(Exception e){
			e.printStackTrace();
			responseData.failue();
		}
 		return responseData;
	}	
	
	
	/**
	 * 获取公告详情
	 */
	@ResponseBody
	@RequestMapping("/js/getNoticeInfoDetail.do")
	@AnoSysLog(actionName="获取资讯详情")
	public ResponseData getAjaxNoticeInfoDetail(int id) {
		LogUtils.info("getAjaxNoticeInfoDetail is comming!");
		ResponseData responseData = new ResponseData();
		try {
			NoticeInfo beanObj = this.noticeInfoService.getById(NoticeInfo.class,id);
			responseData.setData(beanObj);
		} catch (Exception e) {
			e.printStackTrace();
			LogUtils.info("获取资讯详情getAjaxNoticeInfoDetail err",e);
			responseData.failue();
		}
		return responseData;
	}
}
